// 处理时间格式
import moment from 'moment';

class dateHandler {
  // 时间戳转格式化时间
  getFormatTime (time) {
    // 不传参则取当前时间
    if (!time) {
      time = new Date().getTime();
    }
    if (typeof time !== 'number') {
      return console.error('请传时间戳');
    }
    if (time && time.length === 10) {
      time = time * 1000;
    }
    let date = moment(time);
    let obj = {
      year: date.format('YYYY'),
      month: date.format('MM'),
      day: date.format('DD'),
      hours: date.format('HH'),
      minutes: date.format('mm'),
      seconds: date.format('ss'),
      fullYear: date.format('YYYY-MM-DD'),
      fullMonth: date.format('MM-DD'),
      fullTime: date.format('HH:mm:ss'),
      fullHour: date.format('HH:mm'),
      fullDate: date.format('YYYY-MM-DD HH:mm:ss')
    }

    return obj;
    // this.year = date.format('YYYY');
    // this.month = date.format('MM');
    // this.day = date.format('DD');
    // this.hours = date.format('HH');
    // this.minutes = date.format('mm');
    // this.seconds = date.format('ss');
    // this.fullYear = date.format('YYYY-MM-DD');
    // this.fullMonth = date.format('MM-DD');
    // this.fullTime = date.format('HH:mm:ss');
    // this.fullHour = date.format('HH:mm');
    // this.fullDate = date.format('YYYY-MM-DD HH:mm:ss');
  }
}

export default new dateHandler